package com.mvc.viewResolver;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mvc.annotation.Service;
/**
 * json视图解析器
 * @author ZGame
 *
 */
@Service
public class JsonViewResolver implements ViewResolver {

	@Override
	public void render(String resultString, HttpServletRequest request, HttpServletResponse response) {
		try {
			ByteArrayOutputStream outnew = new ByteArrayOutputStream();
			byte[] byteAry = resultString.getBytes("UTF-8");
			response.setContentLength(byteAry.length);
			outnew.writeBytes(byteAry);
			ServletOutputStream out;
			out = response.getOutputStream();
			outnew.writeTo(out);
			outnew.close();
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
